package com.song.study.springclouddemo.controller;

import com.song.study.springclouddemo.nacos.NacosConfig;
import com.song.study.springclouddemo.stream.StreamClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/nacos")
public class NacosConfigController {

    @Autowired
    private NacosConfig nacosConfig;

    @Autowired
    private StreamClient streamClient;

    @GetMapping(value = "/config2/get")
    public Object getConfig2(){
        return nacosConfig.getName() + " age: " + nacosConfig.getAge();
    }

    @GetMapping(path = "/send/message")
    public Object sendMessage(){
        for (int i = 0; i < 10; i++) {
            String message = "message content " + i;
            boolean send = streamClient.output().send(MessageBuilder.withPayload(message).build());
            System.out.println("send result: " + send);
        }

        return "success";
    }
}
